package com.theaf.basemodule.web.controller;

import com.theaf.basemodule.common.condition.UserCondition;
import com.theaf.basemodule.common.dto.user.UserDTO;
import com.theaf.basemodule.common.vo.user.UserVO;
import com.theaf.basemodule.common.api.UserService;
import com.theaf.core.web.ResultHandler;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value="/user")
@Api(value = "/user",description = "用户请求")
public class UserController {
    private Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/list",  method = RequestMethod.POST)
    @ApiOperation(value = "参数查询", notes = "参数查询", response = UserDTO.class)
    public Object list(@RequestBody @ApiParam(name="查询条件",value="传入json格式",required=true) UserCondition condition){
        userService.findByOrganAndPos(34L,true,23L);
        return ResultHandler.success(userService.findByCondition(condition));
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiOperation(value = "保存账户", httpMethod = "POST")
    public Object save(@RequestBody @Validated @ApiParam(name="用户数据",value="传入json格式",required=true)  UserVO userVO){
        return ResultHandler.success(userService.save(userVO));
    }

    @RequestMapping(value = "/delete/{id}",  method = RequestMethod.DELETE)
    @ApiOperation(value = "删除", httpMethod = "DELETE",response = Boolean.class)
    @ApiImplicitParam(value = "用户标识" , name = "id" , dataType = "long" , paramType = "path",required=true)
    public Object delete(@PathVariable Long id){
        userService.deleteById(id);
        return ResultHandler.success(true);
    }

    @RequestMapping(value = "/sendPass/{id}",  method = RequestMethod.PUT)
    @ApiOperation(value = "发送密码", httpMethod = "PUT",response = Boolean.class)
    @ApiImplicitParam(value = "用户标识" , name = "id" , dataType = "long" , paramType = "path",required=true)
    public Object sendPass(@PathVariable("id") Long id){
        userService.sendPassword(id);
        return ResultHandler.success(true);
    }

}
